home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.11 Nov 87 / C string library / PStrLib Demo / Demo_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-20  |  3.5 KB  |  133 lines  |  [TEXT/KAHL]

  1. /*    FILE:        Demo_main.c    */
  2. #include        "Demo.h"
  3.  
  4. DialogPtr        dlogW;
  5. ControlHandle    ctlH[3];
  6. Rect            uiRect[2];
  7. int                pageNo = 1;
  8. Boolean            a_Boolean;
  9. int                a_int;
  10. long            a_long;
  11. float            a_float;
  12. short double    a_shortDbl;
  13. double            a_double;
  14. Str255            a_Str255;
  15.  
  16. pascal void DrawUserItem(theDlog, theItem)
  17. DialogPtr    theDlog;
  18. int            theItem;
  19. {
  20.     if (theItem == 5) 
  21.         DrawPage();    /* defined in Demo_draw.c */
  22.     else     /* theItem must == 6 since there're only 2 userItems */    
  23.         FillRect(&uiRect[1], black);    /* draw the separating line */
  24. }
  25.  
  26. SetupDialog()
  27. {
  28.     auto        int        n, itemType;
  29.     auto        Rect    itemBox;
  30.     auto        Handle    itemHandle;
  31.     
  32.     /* Attempt to make the modeless dialog in the heap */
  33.     if (dlogW = GetNewDialog(512, NIL, -1L)) {
  34.         /*    Fetch & Stash the userItem display Rects
  35.             & the ShowVars, Previous and Next Button
  36.             ContolHandles.  We'll need them for drawing the
  37.             userItems and buttons. Also, install UserItems...
  38.         */
  39.         for (n = 2; n <= 6; ++n) {
  40.             GetDItem(dlogW, n, &itemType, &itemHandle, &itemBox);
  41.             switch (n) {
  42.             case 2:    /* ShowVars Button */
  43.             case 3:    /* Previous Button */
  44.             case 4:    /* Next Button */
  45.                 ctlH[n-2] = (ControlHandle) itemHandle;
  46.                 break;
  47.             case 5:    /* Page Display -- UserItem */
  48.             case 6:    /* Separating Line -- UserItem */
  49.                 uiRect[n-5] = itemBox;
  50.                 /* Install the Drawing Procedure for the UserItems */
  51.                 SetDItem(dlogW, n, itemType, DrawUserItem, &itemBox);
  52.                 break;
  53.             }
  54.         }
  55.         /* Disable the ShowVars and Previous Buttons */
  56.         HiliteControl(ctlH[SHOW_BUT], DISABLE);
  57.         HiliteControl(ctlH[PREV_BUT], DISABLE);
  58.     }
  59.     else {
  60.         ShowVars(1, NIL, PSTR, "\pGetNewDialog() failed...");
  61.         ExitToShell();
  62.     }
  63. }
  64.  
  65. main()
  66. {
  67.     auto    EventRecord        eventRec;
  68.     auto    WindowPtr        frontW;
  69.     auto    DialogPtr        theDlog;
  70.     auto    int                itemHit;
  71.     auto    Boolean            terminated = FALSE;
  72.     
  73.     InitGraf(&thePort);            
  74.     InitFonts();                     
  75.     InitWindows();
  76.     InitMenus();
  77.     TEInit();
  78.     InitDialogs(NIL);
  79.     FlushEvents(everyEvent, NL1);
  80.     SetupDialog();
  81.     ShowWindow(dlogW);
  82.     SetPort(dlogW);
  83.     InitCursor();
  84.     while (!terminated) {
  85.         if (!GetNextEvent(everyEvent, &eventRec))
  86.             continue;
  87.         if (!IsDialogEvent(&eventRec))
  88.             continue;
  89.         if (!DialogSelect(&eventRec, &theDlog, &itemHit))
  90.             continue;
  91.         if (theDlog != dlogW)
  92.             continue;
  93.         switch (itemHit) {
  94.         case 1:    /* Quit Button Hit */
  95.             terminated = TRUE;
  96.             break;
  97.         case 2:    /* ShowVars Button Hit -- do it! */
  98.             /* Set some value to look at... */
  99.             a_Boolean = TRUE;
  100.             a_int = 101;
  101.             a_long = 10101;
  102.             a_float = -12.21;
  103.             a_shortDbl = 654321.123;
  104.             a_double = -987654321.123456;
  105.             PStrCopy("\pThis is a pascal string.", 1, ALL, a_Str255);
  106.             ShowVars(7, "\pa_Boolean", BOOL, &a_Boolean, 
  107.                         "\pa_int", CINT, &a_int,
  108.                         "\pa_long", CLONG, &a_long,
  109.                         "\pa_float", CFLOAT, &a_float,
  110.                         "\pa_shortDbl", CSHORTDBL, &a_shortDbl,
  111.                         "\pa_double", CDBL, &a_double,
  112.                         "\pa_Str255", PSTR, a_Str255);
  113.             break;
  114.         case 3:    /* Previous Button Hit -- adjust pageNo */
  115.             if (--pageNo == FIRST_PAGE)
  116.                 HiliteControl(ctlH[PREV_BUT], DISABLE);
  117.             if (pageNo == LAST_PAGE - 1)
  118.                 HiliteControl(ctlH[NEXT_BUT], ENABLE);
  119.             InvalRect(&dlogW->portRect); /* force update */
  120.             break;
  121.         case 4:    /* Next Button Hit -- adjust pageNo */
  122.             if (++pageNo == FIRST_PAGE + 1)
  123.                 HiliteControl(ctlH[PREV_BUT], ENABLE);
  124.             if (pageNo == LAST_PAGE)
  125.                 HiliteControl(ctlH[NEXT_BUT], DISABLE);
  126.             InvalRect(&dlogW->portRect); /* force update */
  127.             break;
  128.         } 
  129.         HiliteControl(ctlH[SHOW_BUT], (pageNo == SV_PAGE ? ENABLE : DISABLE));
  130.     }
  131.     DisposDialog(dlogW);
  132. }
  133.